<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:ice="http://www.icesoft.com/icefaces/component">
    <h:head>
        <title>Sistema de Administración y Monitoreo</title>
        <ice:outputStyle href="./xmlhttp/css/rime/rime.css" />
        <ice:outputStyle href="css/general.css" />
    </h:head>
    <h:body>

        <ice:form styleClass="main">
            <ace:panel id="header" styleClass="header">
                <span class="h1"> Sistema de Administración y Monitoreo<br/></span>
                <span class="h2">Clúster de Procesamiento Paralelo Uptc</span>
            </ace:panel>
            <ace:panel id="content" styleClass="content">
                <ice:panelTabSet styleClass="tabSet">
                    <!--Tab Hosts-->
                    <ice:panelTab id="panelTab1" label="Hosts">
                        <ice:panelGrid id="panelGrid1">

                            <ice:dataTable id="hostsTable" 
                                           sortColumn="#{hostList.sortColumnName}" 
                                           sortAscending="#{hostList.ascending}" 
                                           value="#{hostList.hostsList}" 
                                           var="item"
                                           rendered="#{hostList.renderedTable}">
                                <!-- COL1 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hostName}" arrow="true">
                                            <ice:outputText value="#{hostList.hostName}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ace:linkButton id="linkBttnActionList"
                                                    value="#{item.hostName}" 
                                                    action="#{hostList.showDetails(item)}"
                                                    style="text-decoration: underline;"/>
                                </ice:column>
                                <!-- COL2 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hostCPU}" arrow="true">
                                            <ice:outputText value="#{hostList.hostCPU}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.hostCPU}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL3  -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.CPUVel}" arrow="true">
                                            <ice:outputText value="#{hostList.CPUVel}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.cpuVel}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL4 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hyperthreading}" arrow="true">
                                            <ice:outputText value="#{hostList.hyperthreading}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.hyperthreading}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL5 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.coreNumber}" arrow="true">
                                            <ice:outputText value="#{hostList.coreNumber}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.coreNumber}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL6 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.useCPU}" arrow="true">
                                            <ice:outputText value="#{hostList.useCPU}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.useOfCPU}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL7 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hostMemory}" arrow="true">
                                            <ice:outputText value="#{hostList.hostMemory}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.memory}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL8 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hostSwap}" arrow="true">
                                            <ice:outputText value="#{hostList.hostSwap}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.swap}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL9 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.memoryUse}" arrow="true">
                                            <ice:outputText value="#{hostList.memoryUse}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.memoryUse}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL10 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.operativeSystem}" arrow="true">
                                            <ice:outputText value="#{hostList.operativeSystem}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.operativeSistem}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL11 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.kernel}" arrow="true">
                                            <ice:outputText value="#{hostList.kernel}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.kernel}">
                                    </ice:outputText>
                                </ice:column>
                                <!-- COL12 -->
                                <ice:column>
                                    <f:facet name="header">
                                        <ice:commandSortHeader columnName="#{hostList.hostType}" arrow="true">
                                            <ice:outputText value="#{hostList.hostType}"></ice:outputText>
                                        </ice:commandSortHeader>
                                    </f:facet>
                                    <ice:outputText styleClass="column"
                                                    value="#{item.hostType}">
                                    </ice:outputText>
                                </ice:column>
                            </ice:dataTable>
                        </ice:panelGrid>

                        <ice:panelBorder id="hostDetail" rendered="#{hostList.renderedDetails}" >
                            <f:facet name="north">
                                <ice:commandButton action="#{hostList.switchRenderedDetails()}" 
                                                   value="Volver"
                                                   image="resources/img/icons/back.png"
                                                   style="margin: 0 10px -8px 0">
                                    <ice:outputText value="Volver"/>
                                </ice:commandButton>
                            </f:facet>
                            <f:facet name="west">
                                <ace:panel style="margin-top: 10px;background: transparent; text-align: center"
                                           header="Host: #{adminHostBean.host.hostName} (#{adminHostBean.host.hostType})">
                                    <ice:commandButton value="Reiniciar" actionListener="#{adminHostBean.restartListener}"/><br/>
                                    <ace:dataTable value="#{adminHostBean.host.properties}"
                                                   var="property">
                                        <ace:column>
                                            <ice:outputText value="#{property}"/>
                                        </ace:column>
                                    </ace:dataTable>
                                </ace:panel>
                            </f:facet>

                            <f:facet name="center">
                                <ice:panelTabSet visible="#{!terminalBean.visibleTerm}">
                                    <ice:panelTab id="services" label="Servicios">
                                        <ice:panelGroup style="text-align: right">
                                            <ice:commandButton onclick="addServiceDialog.show();"
                                                               styleClass="actButton"
                                                               value="Agregar Demonio" 
                                                               actionListener="#{adminHostBean.clearFields}"
                                                               image="resources/img/icons/add.png"
                                                               title="Agregar Demonio"/>

                                            <ice:commandButton value="Editar Demonio"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.loadItemInfo()}"
                                                               image="resources/img/icons/edit.png"
                                                               onclick="addServiceDialog.show();"
                                                               title="Editar Demonio"/>

                                            <ice:commandButton value="Eliminar Demonio"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.deleteService}"
                                                               image="resources/img/icons/delete.png"
                                                               title="Eliminar Demonio"/>

                                            <ice:commandButton id="a1" value="Iniciar servicio"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.adminDaemon}"
                                                               image="resources/img/icons/start.png"
                                                               title="Iniciar servicio"/>

                                            <ice:commandButton id="a2" value="Reiniciar"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.adminDaemon}"
                                                               image="resources/img/icons/restart.png"
                                                               title="Reiniciar servicio"/>

                                            <ice:commandButton id="a0" value="Parar"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.adminDaemon}"
                                                               image="resources/img/icons/stop.png"
                                                               title="Parar servicio"/>

                                            <ice:commandButton value="Abrir terminal"
                                                               styleClass="actButton"
                                                               actionListener="#{terminalBean.showTerminal}"
                                                               image="resources/img/icons/terminal.png"
                                                               title="Abrir terminal"/>
                                        </ice:panelGroup>

                                        <ice:dataTable id="servicesTable"
                                                       style="width: 100%"
                                                       value="#{adminHostBean.host.serviceList}" 
                                                       var="service">
                                            <ace:column>
                                                <ice:rowSelector id="selected"
                                                                 value="#{adminHostBean.selectedServiceRow[service]}"       
                                                                 preStyleOnSelection="true"
                                                                 selectionListener="#{adminHostBean.serviceSelectionListener}"
                                                                 />

                                                <f:facet name="header">
                                                    <ice:outputText value="Nombre"></ice:outputText>
                                                </f:facet>
                                                <ice:outputText value="#{service.daemonName}"></ice:outputText>
                                            </ace:column>
                                            <ace:column>
                                                <f:facet name="header">
                                                    <ice:outputText value="Estado"></ice:outputText>
                                                </f:facet>
                                                <ice:outputText id="a3" value="#{service.statusCommand}"></ice:outputText>
                                            </ace:column>
                                            <ace:column>
                                                <f:facet name="header">
                                                    <ice:outputText value="Tiempo de ejecución"></ice:outputText>
                                                </f:facet>
                                                <ice:outputText value="#{service.uptime}"></ice:outputText>
                                            </ace:column>
                                        </ice:dataTable>
                                    </ice:panelTab>
                                    <ice:panelTab id="files" label="Archivos de Configuracion">
                                        <ice:panelGroup style="text-align: right">
                                            <ice:commandButton styleClass="actButton"
                                                               value="Agregar Archivo" 
                                                               actionListener="#{adminItemsBean.clearFields}"
                                                               image="resources/img/icons/add.png"
                                                               onclick="addingDialog.show();"
                                                               title="Agregar Archivo"/>
                                            <ice:commandButton value="Editar Archivo"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.execDaemonComand}"
                                                               image="resources/img/icons/edit.png"
                                                               title="Editar Archivo"/>

                                            <ice:commandButton value="Eliminar Archivo"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.execDaemonComand}"
                                                               image="resources/img/icons/delete.png"
                                                               title="Eliminar Archivo"/>

                                            <ice:commandButton value="Ver Archivo"
                                                               styleClass="actButton"
                                                               actionListener="#{adminHostBean.execDaemonComand}"
                                                               image="resources/img/icons/viewFile.png"
                                                               title="Ver Archivo"/>
                                        </ice:panelGroup>
                                        <ice:dataTable id="filesTable"
                                                       style="width: 100%"
                                                       value="#{adminHostBean.host.fileList}" 
                                                       var="file">
                                            <ace:column>
                                                <ice:rowSelector id="selected"
                                                                 value="#{adminHostBean.selectedFileRow[file]}"       
                                                                 preStyleOnSelection="true"
                                                                 selectionListener="#{adminHostBean.fileSelectionListener}"
                                                                 />

                                                <f:facet name="header">
                                                    <ice:outputText value="Nombre"></ice:outputText>
                                                </f:facet>
                                                <ice:outputText value="#{file.name}"></ice:outputText>
                                            </ace:column>
                                            <ace:column>
                                                <f:facet name="header">
                                                    <ice:outputText value="Path"></ice:outputText>
                                                </f:facet>
                                                <ice:outputText value="#{file.path}"></ice:outputText>
                                            </ace:column>
                                        </ice:dataTable>
                                    </ice:panelTab>
                                </ice:panelTabSet>

                                <ice:panelGrid width="100%" visible="#{terminalBean.visibleTerm}">
                                    <ace:linkButton value="Cerrar Terminal" actionListener="#{terminalBean.showTerminal}"/>

                                    <form id="termForm" action="#{terminalBean.sendCommand()}" style="background: black">
                                        <ice:panelGroup style="background: black; text-align: left; padding: 5px;
                                                        font: 14px monospace;margin-bottom: -5px">

                                            <h:outputLabel value="#{terminalBean.prompt}"  for="commandInput" style="color: white;padding: 3px;"/>
                                            <h:inputText id="commandInput"
                                                         style="width: 70%;color: white;background: black;border:none;border-bottom: solid 2px;"
                                                         value="#{terminalBean.command}">
                                            </h:inputText>
                                        </ice:panelGroup>
                                        <ice:panelGrid style="background: black;width: 100%;">
                                            <ice:inputTextarea value="#{terminalBean.commandOut}" readonly="true" 
                                                               style="resize: none;color:white;font: 14px monospace; 
                                                               width: 98%;background: black;height: 300px;"/>

                                        </ice:panelGrid>
                                    </form>
                                </ice:panelGrid>
                            </f:facet>
                        </ice:panelBorder>

                    </ice:panelTab>

                    <ice:panelTab id="panelTab2" label="Jobs">
                        <ice:panelGrid id="panelGrid2" >

                        </ice:panelGrid>
                    </ice:panelTab>
                    <ice:panelTab id="panelTab3" label="Usuarios">
                        <ice:panelGrid id="panelGrid3" >
                            <ice:outputText  id="outputText3" value="Tab3"/>
                        </ice:panelGrid>
                    </ice:panelTab>
                </ice:panelTabSet>
            </ace:panel>
            <ace:panel id="footer" styleClass="footer">
                footer
            </ace:panel>
            <ace:dialog id="addServiceDialog"
                        header="Servicio"
                        widgetVar="addServiceDialog"
                        closable="true"
                        modal="true"
                        draggable="false"
                        showEffect="clip"
                        hideEffect="fade"
                        width="500"
                        resizable="false">

                <h:form id="inputForm" >
                    <h:panelGrid style="text-align: left;" columns="2" width="100%">
                        <h:outputLabel  id="nameLabel" for="name" value="Nombre:"/>
                        <h:inputText id="name" value="#{adminHostBean.name}" />

                        <h:outputLabel id="statusLabel" for="status" value="Comando de estado:"/>
                        <h:inputText  id="status" value="#{adminHostBean.status}"/>

                        <h:outputLabel  id="startLabel" for="start" value="Comando de inicio:"/>
                        <h:inputText  id="start" value="#{adminHostBean.start}"/>

                        <h:outputLabel  id="restartLabel" for="restart" value="Comando de reinicio:"/>
                        <h:inputText  id="restart" value="#{adminHostBean.restart}"/>

                        <h:outputLabel  id="stopLabel" for="stop" value="Comando de parada:"/>
                        <h:inputText  id="stop" value="#{adminHostBean.stop}"/>
                    </h:panelGrid>
                    <h:commandButton id="submitService" value="Agregar Servicio" 
                                     onclick="addServiceDialog.hide();"
                                     actionListener="#{adminHostBean.addService}"/>
                </h:form>
            </ace:dialog>

        </ice:form>
    </h:body>
</html>